<html>
	<head>
		<title>
			Testing Debounce
		</title>
		<script type="text/javascript">
			var keyBuffer = [];
			function init() {
				document.getElementById("inputField").onkeypress = keyPressEvent;
			}

			function keyPressEvent(eventObject) {
				var charCode = eventObject.which ? eventObject.which : eventObject.keyCode;
				if(charCode != 13) {
					keyBuffer.push(charCode);
				} else {
					document.getElementById("text").value = String.fromCharCode.apply(null, keyBuffer);
					keyBuffer = [];
				}
			}
			
			function debounceCheck(val) {
				var valNew = document.getElementById("inputField").value;
				console.log("value when key up occurred : " + val);
				console.log("value some ms after key up : " + valNew);
				if(valNew == val) {
					registerValue(val);
				}
			}
			
			var registered = {};
			function registerValue(value) {
				!registered[value] && console.log("Registered : " + value);
				registered[value] = true;				
				//var currentValue = document.getElementById("text").value;
				//document.getElementById("text").value = currentValue + "\n" + value;
			}
		</script>
	</head>
	<body onload = init();>
		Enter Text<input id="inputField" type="text"/>
		<br />
		Registered Words<textarea id="text" style="height:100px;width:100px;"></textarea>
	</body>
</html>